<template lang="html">
    <div class="messageedit">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;修改消息</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-form ref="form" label-width="120px">
                <el-form-item label="ID：">
                    <el-input v-model="id" :disabled="true" style="width:360px"></el-input>
                </el-form-item>
                <el-form-item label="类型：">
                    <el-select v-model="type" @change="changeType" placeholder="请选择类型">
                        <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="内容(中文)：">
                    <el-input v-model="contentCn"></el-input>
                </el-form-item>
                <el-form-item label="内容(英文)：">
                    <el-input v-model="contentEn"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="width:150px" type="primary" @click="submit()">确认修改</el-button>
                    <router-link to="/message"><el-button style="width:150px" type="primary">返回列表</el-button></router-link>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import {getMessageList,postMessageEdit} from '@/api/message/list'
    export default {
        name: "messageedit",
        components:{
        
        },
        data() {
            return {
                id:0,//列表id
                type:'',//标题
                contentCn:'',//中文内容
                contentEn:'',//英文内容
                options:[
                    {
                        value:1,
                        label:"系统"
                    },
                    {
                        value:2,
                        label:"交易"
                    }
                ],
            }
        },
        created(){
            //获取id
            if(this.$route.query.id || this.$route.query.id != ''){
                this.id = this.$route.query.id;
            }
            //获取数据
           this.getMessageList();
        },
        mounted() {
            
        },
        methods: {
            //获取列表
           getMessageList(){
                var that = this;
                var pageIndex = 1;
                var pageSize = 10;
                getMessageList(pageIndex,pageSize).then(res => {
                    var list = res.data.list;
                    //获取详情数据
                    list.forEach(function(val,index){
                        if(that.id == val.id){
                            that.type = val.type;
                            that.id = val.id;
                            that.contentCn = val.content_cn;
                            that.contentEn = val.content_en;
                        }
                    })
                })
            },
            //type类型
            changeType(type){
                this.type = type;
            },
            //确认提交修改  
            submit(){
                if(this.contentCn == ''){
                    this.$message({
                        message: '请输入中文内容！',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.contentEn == ''){
                    this.$message({
                        message: '请输入英文内容！',
                        type: 'warning'
                    });
                    return false;
                }
                //保存修改
                postMessageEdit(this.id,this.type,this.contentCn,this.contentEn).then(res => {
                    if(res.code == 200){
                        this.$message({
                            message: '修改成功！',
                            type: 'success'
                        });
                    }else {
                        this.$message.error('修改失败！');
                    }
                })
            },
        }
    }
</script>

<style lang="css">

</style>
